using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace GearBlog.Web.ViewComponents
{
	using Castle.MonoRail.Framework;
	using Castle.Windsor;
	using Castle.Windsor.Configuration.Interpreters;
	using GearBlog.Web.Services;

	public class FileUploadComponent:ExtendedViewComponentBase
	{
		private string _storageKey;
		private string _fileListView;
		[ViewComponentParam(Required=true)]
		public string StorageKey
		{
			get { return _storageKey; }
			set { _storageKey = value; }
		}

		[ViewComponentParam(Required = true)]
		public string FileListView
		{
			get { return _fileListView; }
			set { _fileListView = value; }
		}

		public override void Initialize()
		{
			IFileStorageService fileStorage = ServiceContainer.Resolve<IFileStorageService>();
			PropertyBag["fileListView"] = _fileListView;
			PropertyBag["fullFileListView"] = string.Format("common/filelist/{0}.vm", _fileListView);
			PropertyBag["fileList"] = fileStorage.GetFiles(_storageKey, RailsContext);
			PropertyBag["storageKey"] = _storageKey;
		}
	}

	public class ExtendedViewComponentBase:ViewComponent
	{
		private IWindsorContainer _serviceContainer;

		protected ExtendedViewComponentBase()
		{
			_serviceContainer= new WindsorContainer(new XmlInterpreter());
		}
		protected IWindsorContainer ServiceContainer
		{
			get { return _serviceContainer; }
		}
	}
}
